﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace Autorent.Desktop.Main.Validations
{
    /// <summary>
    /// Validate if only numbers presents
    /// </summary>
    public class OnlyNumbersRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            if (IsCharConsists(value as string)) return new ValidationResult(false, "Mileage field can't contain symbols...");

            return new ValidationResult(true, null);
        }

        private bool IsCharConsists(string value)
        {
            bool isChar = false;

            foreach (char c in value)
            {
                if (!Char.IsDigit(c))
                {
                    isChar = true;
                }
            }

            return isChar;
        }
    }
}
